package com.unionfetch.content_home.model

import com.google.gson.Gson
import com.unionfetch.content_home.api.HomeApiManager
import com.unionfetch.content_home.bean.request.FirstStepRequest
import com.unionfetch.content_home.bean.request.SecondStepRequest
import com.unionfetch.content_home.bean.request.ThirdStepIbRequest
import com.unionfetch.content_home.bean.request.ThirdStepRequest
import com.unionfetch.content_home.contract.OpenAccountContract
import com.unionftech.common.base.mvp.impl.BaseModel
import com.unionftech.common.base.mvp.impl.IBaseCallBack
import com.unionftech.common.bean.ResponseResult
import com.unionftech.common.network.SimpleNetWork
import okhttp3.RequestBody.Companion.toRequestBody

class OpenAccountModel : BaseModel(), OpenAccountContract.IOpenAccountModel {
    private val mGson by lazy { Gson() }
    override fun handleFirstStep(
        token: String,
        request: FirstStepRequest,
        callBack: IBaseCallBack<ResponseResult<Any?>>
    ) {
        execute {
            val result = request {
                val json = mGson.toJson(request, FirstStepRequest::class.java)
                val requestBody = json.toRequestBody(SimpleNetWork.JSON)
                HomeApiManager.getInstance().apiOpenAccount().submitBaseInfo(token, requestBody)
            }
            callBack.onResponse(result)
        }
    }

    override fun handleSecondStep(
        token: String,
        request: SecondStepRequest,
        callBack: IBaseCallBack<ResponseResult<Any?>>
    ) {
        execute {
            val result = request {
                val json = mGson.toJson(request, SecondStepRequest::class.java)
                val requestBody = json.toRequestBody(SimpleNetWork.JSON)
                HomeApiManager.getInstance().apiOpenAccount().submitRCAsset(token, requestBody)
            }
            callBack.onResponse(result)
        }
    }

    override fun handleRCThirdStep(
        token: String,
        request: ThirdStepRequest,
        callBack: IBaseCallBack<ResponseResult<Any?>>
    ) {
        execute {
            val result = request {
                val json = mGson.toJson(request, ThirdStepRequest::class.java)
                val requestBody = json.toRequestBody(SimpleNetWork.JSON)
                HomeApiManager.getInstance().apiOpenAccount().submitRCAccount(token, requestBody)
            }
            callBack.onResponse(result)
        }
    }

    override fun handleIBThirdStep(
        token: String,
        request: ThirdStepIbRequest,
        callBack: IBaseCallBack<ResponseResult<Any?>>
    ) {
        execute {
            val result = request {
                val json = mGson.toJson(request, ThirdStepIbRequest::class.java)
                val requestBody = json.toRequestBody(SimpleNetWork.JSON)
                HomeApiManager.getInstance().apiOpenAccount().ibOpenTrade(token, requestBody)
            }
            callBack.onResponse(result)
        }
    }
}